package com.shenhaofeng.app.http;

import com.shenhaofeng.app.http.request.Request;
import com.shenhaofeng.app.http.response.Response;


/**
 * Created by Administrator on 2016/10/14.
 */
public class Result<T> {

    private Exception exception;

    private T data;

    private Response response;

    private Request request;



    private Result(Builder<T> builder) {
        this.exception = builder.exception;
        this.data = builder.data;
        this.response = builder.response;
        this.request = builder.request;
    }


    public boolean isError() {
        return exception != null;
    }


    public T data() {
        return data;
    }


    public Exception exception() {
        return exception;
    }


    public Response response() {
        return response;
    }


    public Request request() {
        return request;
    }


    public static class Builder<T> {

        private Class<T> cls;

        private Exception exception;

        private T data;

        private Response response;

        private Request request;


        public Builder(Class<T> cls) {
            this.cls = cls;
        }


        public Builder<T> exception(Exception e) {
            this.exception = e;
            return this;
        }


        public Builder<T> data(T data) {
            this.data = data;
            return this;
        }


        public Builder<T> response(Response response) {
            this.response = response;
            return this;
        }


        public Builder<T> request(Request request) {
            this.request = request;
            return this;
        }


        public Result<T> build() {
            return new Result<>(this);
        }


    }

}
